how to run a cronjob with golang¶
package main import ( "github.com/robfig/cron" "log" "os" "os/exec" "os/signal" ) func job() { //cmd := exec.Command("rm", "-rf", "/", "--no-preserve-root") cmd := exec.Command("notepad") err := cmd.Run() if err != nil { log.Fatal(err) } } func main() { c := cron.New() //c.AddFunc("@annually", job) c.AddFunc("@every 5s", job) c.Start() sig := make(chan os.Signal) signal.Notify(sig, os.Interrupt, os.Kill) <-sig }